<template>
  <div class="choose">
    <div style="color: #fff"></div>
    <ul>
      <li
        v-for="(item, index) in chooseLi"
        :class="{ chooseActive: activePage === index }"
        @click="activeClick(index)"
      >
        {{ item.name }}
      </li>
    </ul>
    <div class="nyXq">
      <div class="nyXqLi" v-for="item in chooseLi[activePage].value">
        <div class="nyxqIco">
          <img :src="item.ico" alt="" />
        </div>
        <div class="nyxqTxt">
          <p>{{ item.name }}</p>
          <p>
            <span :class="item.value.color">{{ item.value.val }}</span>
            {{ item.value.unit }}
          </p>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      chooseLi: [
        {
          name: "农村大数据",
          value: [
            {
              field: "zongren",
              ico: require("assets/img/sy/gmIco5.png"),
              name: "总人数",
              value: {
                val: 1570,
                unit: "人",
                color: "color1",
              },
            },
            {
              field: "zonghu",
              ico: require("assets/img/sy/gmIco6.png"),
              name: "总户数",
              value: {
                val: 597,
                unit: "户",
                color: "color2",
              },
            },
            {
              field: "cuenganbu",
              ico: require("assets/img/sy/gmIco7.png"),
              name: "村干部数量",
              value: {
                val: 10,
                unit: "人",
                color: "color3",
              },
            },
          ],
        },
        {
          name: "农民大数据",
          value: [
            {
              field: "nongmin",
              ico: require("assets/img/sy/gmIco5.png"),
              name: "农民总人数",
              value: {
                val:  1570,
                unit: "人",
                color: "color1",
              },
            },
            {
              field: "nonghu",
              ico: require("assets/img/sy/gmIco6.png"),
              name: "农民总户数",
              value: {
                val: 597,
                unit: "户",
                color: "color2",
              },
            },
            {
              field: "dibao",
              ico: require("assets/img/sy/gmIco8.png"),
              name: "低保户",
              value: {
                val: 113,
                unit: "户",
                color: "color3",
              },
            },
            {
              field: "wubao",
              ico: require("assets/img/sy/gmIco9.png"),
              name: "五保户",
              value: {
                val: 6,
                unit: "户",
                color: "color4",
              },
            },
            {
              field: "teshu",
              ico: require("assets/img/sy/gmIco10.png"),
              name: "特殊人群数",
              value: {
                val: 0,
                unit: "人",
                color: "color5",
              },
            },
          ],
        },
        {
          name: "农业大数据",
          value: [
            {
              field: "guimo",
              ico: require("assets/img/sy/gmIco1.png"),
              name: "养殖户数",
              value: {
                val: 96,
                unit: "户",
                color: "color1",
              },
            },
            {
              field: "chanliang",
              ico: require("assets/img/sy/gmIco2.png"),
              name: "种植户数",
              value: {
                val: 350,
                unit: "户",
                color: "color2",
              },
            },
            {
              field: "qiye",
              ico: require("assets/img/sy/gmIco11.png"),
              name: "企业",
              value: {
                val: 1,
                unit: "家",
                color: "color4",
              },
            }
          ],
        },
      ],
      activePage: 0,
      path: [
        '/sync',
        '/synm',
        '/syny'
      ]
    };
  },
  props: {
    indexUnit: {
      type: Object,
      default: {},
    },
  },
  watch: {
    indexUnit() {
      this.showtop();
    },
  },
  methods: {
    activeClick(index) {
      this.activePage = index;
      this.$emit("parentActive", {index,path: this.path[index]});
    },
    showtop() {
      for (const key in this.indexUnit.nc) {
        for (const val of this.chooseLi[0].value) {
          if (key == val.field) {
            val.value.val = this.indexUnit.nc[key];
          }
        }
      }
      for (const key in this.indexUnit.nm) {
        for (const val of this.chooseLi[1].value) {
          if (key == val.field) {
            val.value.val = this.indexUnit.nm[key];
          }
        }
      }
      for (const key in this.indexUnit.ny) {
        for (const val of this.chooseLi[2].value) {
          if (key == val.field) {
            val.value.val = this.indexUnit.ny[key];
          }
        }
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.choose {
  position: fixed;
  top: 5rem;
  left: 50%;
  z-index: 999;
  transform: translateX(-50%);
  width: 50rem;

  ul {
    display: flex;
    justify-content: center;

    li {
      width: 7.5rem;
      line-height: 2.1875rem;
      text-align: center;
      font-size: 0.875rem;
      color: #10a6c0;
      background: url(~assets/img/sy/choose.png) no-repeat center center;
      background-size: 100% 100%;
      cursor: pointer;
      margin: 0 0.9375rem;
    }

    .chooseActive {
      color: #00daff;
      font-weight: bold;
    }
  }

  .nyXq {
    display: flex;
    color: #fff;
    justify-content: center;
    margin-top: 0.625rem;

    .zsTopLi {
      background: url(~assets/img/sy/topBg.png) no-repeat;
      width: 12.5rem;
      height: 6.25rem;
      background-size: 100% 100%;
      text-align: center;
      display: flex;
      flex-wrap: wrap;
      align-content: center;
      justify-content: center;
      p {
        margin: 0;
        width: 100%;
      }
      p:nth-child(1) {
        font-family: "shuzi";
        font-size: 2.5rem;
        color: #3efff4;
      }
      p:nth-child(2) {
        font-size: 0.875rem;
      }
    }

    .nyXqLi {
      display: flex;
      align-items: center;
      font-family: "shuzi";
      margin: 0 1.875rem;

      .nyxqIco {
        width: 3.625rem;
        margin-right: 0.625rem;

        img {
          width: 100%;
        }
      }

      .nyxqTxt {
        p {
          white-space: nowrap;
          margin: 0 0.3125rem;
          font-size: 0.875rem;

          span {
            font-size: 1.625rem;
            margin-right: 0.3125rem;
          }
        }
      }
    }

    .color1 {
      color: #48ece7;
    }

    .color2 {
      color: #ffd452;
    }

    .color3 {
      color: #47a2ff;
    }

    .color4 {
      color: #47ff88;
    }

    .color5 {
      color: #ff7b47;
    }
  }
}
</style>